#ifndef AI_INTEGRATION_H
#define AI_INTEGRATION_H

#include <string>
#include <map>
#include <vector>

struct AIResponse {
    std::string content;
    bool success;
    std::string error_message;
};

class AIIntegration {
public:
    AIIntegration();
    ~AIIntegration();

    // Initialize AI service
    bool initialize(const std::string& api_key, const std::string& base_url = "");

    // Send query to AI
    AIResponse query(const std::string& message, const std::string& session_id = "");

    // Set system prompt
    void setSystemPrompt(const std::string& prompt);

    // Clear session history
    bool clearSession(const std::string& session_id);

    // Get session history
    std::vector<std::string> getSessionHistory(const std::string& session_id);

private:
    std::string api_key_;
    std::string base_url_;
    std::string system_prompt_;
    std::map<std::string, std::vector<std::string>> session_histories_;

    // HTTP request
    std::string makeHttpPostRequest(const std::string& url, const std::string& json_body);

    // Build request JSON
    std::string buildRequestJson(const std::string& message, const std::vector<std::string>& history);

    // Parse response JSON
    AIResponse parseResponseJson(const std::string& response);

    // JSON utility function
    std::string escapeJson(const std::string& str);
    
    // Generate mock response for demo mode
    std::string generateMockResponse(const std::string& query) const;
};

#endif // AI_INTEGRATION_H